<?php
/**
 * Created by PhpStorm.
 * User: 82508
 * Date: 2017/12/9
 * Time: 22:43
 */

@header("Content-type: text/html; charset=utf-8");
//链接数据库
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'root';
$link = mysqli_connect($dbhost, $dbuser, $dbpass, "login0");
//注册
$username = $_POST["username"];
$pwd = $_POST["pwd"];
$pwd2 = $_POST["pwd2"];
$email = $_POST["email"];
$emailMa = $_POST["emailMa"];
//var_dump($username);
//var_dump($pwd);
//var_dump($pwd2);

if ($email == "") {
    exit("邮箱不能为空");
}
if ($emailMa == "") {
    exit("邮箱验证不能为空");
}
if ($username == "") {
    exit("用户名不能为空");
}
if ($pwd == "" && $pwd2 == "") {
    exit("密码不能为空");
}
if ($pwd != $pwd2) {
    exit("两次密码不一致");
}
if ($link) {
    mysqli_query($link, "set names utf8");
    $pwd = md5($pwd);
    $sql = "insert into user(username,pwd)values('{$username}','{$pwd}')";
    mysqli_query($link, $sql);
    if (mysqli_affected_rows($link) == 1) {
        echo "hi " . $username . " 注册成功";
    } else {
        echo "注册失败";
    }
}

?>